let sest;
let article;
let hotTitle;

$(function() {
	sest = sessionStorage;
	article = $("#article");
	hotTitle = $("#hot-title");
	articles();
	hotTitles();
	exec();
});

let exec = function() {
	$("body").on("click", "[data-newsId]", function() {
		sest.setItem("articleNewsId", $(this).data("newsid"));
	});
};

let articles = function () {
	$.ajax({
		type: "get",
		url: "/photo/user-article.do",
		async: true,
		data: {photoWriterId:sessionStorage.author},
		success: function(data) {
			console.info(data);
			$.each(data, function(i, n) {
				let lis = list01.clone().appendTo(article);
				$.each(n, function(j, k) {
					lis.find("._"+j).text(k);
				});
				lis.find("[data-newsId]").attr("data-newsId", n.newsId);
				lis.find("[data-newsClassId]").attr("data-newsClassId", n.newsClassId);
			});
		}
	});
}

let hotTitles = function() {
	$.ajax({
		type: "get",
		url: "/photo/user-article.do",
		async: true,
		data: {photoWriterId:sessionStorage.author},
		success: function(data) {
			//console.info(data);
			hotTitle.empty();
			$.each(data, function(i, n) {
				let li = lis.clone().attr("data-newsId", n.newsId).attr("data-newsClassId", n.newsClassId).appendTo(hotTitle);
				li.find("a").text(n.newsTitle);
			});
		}
	});
}

let list01 = $(`<div class="pui_list_img_txt">
	<div class="item clearfix" data-newsId data-newsClassId>
		<div class="lbox">
			<a href="article.html" target="_blank" style="width: 238px; height: 160px; background: rgba(0, 0, 0, 0);">
				<div class="fade-box"></div> <img data-src="img/sony.jpg" class="" src="img/sony.jpg" style="opacity: 1; display: block; margin-left: 0px; height: 100%; width: auto; margin-top: auto;" width="" height=""></a>
		</div>
		<div class="rbox" style="width: 544px;">
			<a href="article.html" target="_blank">
				<h3 class="_newsTitle"></h3></a>
			<div class="des"><span class="_newsWorker"></span></div>
			<ul class="list clearfix">
				<li><i class="iconfont icon-view _newsTime"></i></li>
			</ul>
		</div>
	</div>
</div>`);

let lis = $(`
	<li>
		<a href="article.html" target="_blank" class="_newsTitle"></a>
	</li>
`);
